package com.shujia.wyh.day20;

import java.util.HashSet;

/*
        使用Set集合存储自定义对象
 */
public class SetDemo2 {
    public static void main(String[] args) {
        //创建Set集合对象
        HashSet<Student2> set = new HashSet<>();

        //创建学生对象
        Student2 s1 = new Student2("小虎", 18);
        Student2 s2 = new Student2("theshy", 19);
        Student2 s3 = new Student2("uzi", 20);
        Student2 s4 = new Student2("xiaoming", 17);
        Student2 s5 = new Student2("小虎", 18);

        //向集合中添加自定义对象
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        set.add(s5);

        //遍历集合
        for (Student2 student2 : set) {
            System.out.println(student2);
        }

    }
}
